package entrust

/**
 * 委托 by
 * 委托类覆盖实现类中方法
 */
interface OverrideBase {
    val message: String

    fun printMessage()
    fun printMessageLine()
}

class OverrideBaseImpl(val x: Int) : OverrideBase {
    override val message ="Impl Message to $x"

    override fun printMessage() {
        print(message)
    }

    override fun printMessageLine() {
        println(message)
    }
}

class OverrideDerived(b: OverrideBase) : OverrideBase by b {

    //不会覆盖委托对象的成员属性
    override val message="OverrideDerived Mesage"

    /**
     * 会覆盖委托对象中的方法
     */
    override fun printMessage() {
        print("abc")
    }
}

fun main(args: Array<String>) {
    val b = OverrideBaseImpl(10)
    val derived =OverrideDerived(b)
    derived.printMessage()
    derived.printMessageLine()
    println(derived.message)
}